#include "plane.hpp"

Plane::Plane(Material* _material,const Vector& _point,const Vector& _normal) : point(_point) , normal(_normal)
 {
	material = _material;
	normal = _normal.normalize();
}

double Plane::intersection(const Ray& _ray,Vector& _point) {
	
	const double n_dot_d = normal.dot_product(_ray.get_direction());
	
	if(n_dot_d < 0.0) {
		const double distance = (normal.dot_product(point.sub_vect(_ray.get_origin()))) / (n_dot_d);
		if(distance >= 0.0 && distance <= 7.5) { 
			_point.set(
				_ray.get_origin().x + distance*_ray.get_direction().x,
				_ray.get_origin().y + distance*_ray.get_direction().y,
				_ray.get_origin().z + distance*_ray.get_direction().z
			);
			return distance;	
		}
	}
	return 90.0;
	
}

Vector Plane::get_normal(const Vector& _point) const { return normal; }

Vector Plane::get_point(void) const { return point; }


